package com.laoye.mapper;


import com.laoye.bean.Product;
import com.laoye.dto.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductMapper  {

    void addProduct(@Param("product") Product product);

    List<Product> getAllProducts(@Param("prod_name") String prod_name,
                                 @Param("category") String category,
                                 @Param("status") Byte status
    );

    void updateProduct(@Param("product") Product  product);

    @Update("update product set status=#{StatusDTO.status} where id=#{StatusDTO.id}")
    void updateStatus(@Param("StatusDTO")StatusDTO statusDTO);

    @Select("select id,prod_name,price,image_url from product where status=1")
    List<ProdSimpleDTO> getSimpleProduct();

    @Select("select * from product where id=#{id}")
    ProductInfoDTO getProductById(@Param("id") Integer id);

    @Select("select store from product where id=#{id}")
    Integer getStore(@Param("id") Integer id);

    List<ProdSimpleDTO> getSimpleProductByCategory(@Param("category")String  category,@Param("prod_name") String prod_name);

    @Update("update product set store=store-#{param.count} where id=#{param.id}")
    void updateStore(@Param("param")ProductStoreDTO productStoreDTO);
}
